#include "m01_buram.h"

namespace igslib
{
    m01_buram::m01_buram()
    {
        //rd.start_addr = nullptr;
        //rd.block_length = 262140;
        offset = 0;
        int get_ram_result =Get_Ram(&rd,map_name_to_id());
        if (get_ram_result < 0)
        {
            std::stringstream ss;
            ss << __func__ << "> Get_Ram() result= " << get_ram_result;
            ss << ",id=" << map_name_to_id();
            throw_igslib_exception(ss.str());
        }
    }
    int m01_buram::GetSize()
    {
        int rtn = 0;
        rtn = rd.block_length;
        return rtn;
    }
    int m01_buram::map_name_to_id()
    {
        int rtn = 0;
        return rtn;
    }
    void* m01_buram::BindBlock(int size)
    {
        void* rtn = nullptr;
        char* point = (char*)rd.start_addr;
        util::Log("point %p : rd.start_addr %p \n",point,rd.start_addr);
        
        rtn = (void*)point;
        point += size;
        util::Log("point %p : rd.start_addr %p \n",point,rd.start_addr);
        offset += size;

        if (size < 0)
        {
            rtn = nullptr;
        }

        if (offset >= GetSize())
        {
           rtn = nullptr;
           util::Log("offset >= GetSize()\n");
        }

        return rtn;
    }
};
